package com.lbt.javaSE.Alog;

public class Linked {
     public static class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }

    public static int[] reversePrint(ListNode head) {
        String str=null;
        while(head!=null){
            if(str==null) {
                str=String.valueOf(head.val) ;
            }else {
                str=str+" "+head.val;
            }
            head=head.next;
        }
        if(str==null) return  new int[0];
        String[] strs = str.split(" ");
        int number=strs.length;
        int result[]=new int[number];
        for(int i=0;i<strs.length;i++){
            result[i]=Integer.valueOf(strs[number-1-i]);
        }
        return result;
    }

    public static void main(String[] args) {
        ListNode head=new ListNode(3);
        ListNode firstNode = new ListNode(2);
        ListNode secondNode = new ListNode(1);
        head.next=firstNode;
        firstNode.next=secondNode;
        secondNode.next=null;
        int[] ints = reversePrint(head);
        for(int bs:ints){
            System.out.print(bs+"\t");
        }

    }

}
